<template>
  <div class="attendance" @mouseenter="amListShow = true" @mouseleave="amListShow = false">
      <el-dropdown trigger="click" @command="handleCommand">
      <span>
        出车统计<i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command='按出行距离统计'>按出行距离统计</el-dropdown-item>
        <el-dropdown-item command='按作业点数统计'>按作业点数统计</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <div
      class="attendance_work_time attendanceMonth_records"
      v-if="show"
      @mouseenter="amListShow = false"
    >
      <h2>
        <span class="iconfont icon-icon-xin_kaoqinjilu"></span>
        <span>{{titleWindow}}</span>
        <i class="iconfont icon-guanbi" @click="closeWindow"></i>
      </h2>
      <div class="attendance_records_content">
        <div class="top_box">
          <el-form inline class="demo-form-inline">
            <el-form-item label="日期：" class="minwidth230">
              <el-date-picker
                v-model="date"
                type="date"
                placeholder="请选择日期"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
            <el-form-item :label="titlePara">
              <el-input v-model="para" placeholder="1"></el-input>
            </el-form-item>
            <!-- <el-form-item label="班组：" class="minwidth230">
              <el-select v-model="teamValue" placeholder="请选择班组">
                <el-option
                  v-for="item in attendanceMonth.records.teamList"
                  :key="item.CLIENT_NAME"
                  :label="item.CLIENT_NAME"
                  :value="item.CLIENT_NAME"
                ></el-option>
              </el-select>
            </el-form-item> -->
            <div class="records_btns">
              <el-button type="primary" @click="search">查 询</el-button>
              <!-- <el-button type="success" @click="exportRowExcelMonth">导 出</el-button> -->
            </div>
          </el-form>
        </div>
        <div class="table_list">
          <el-table
            :data="list"
            style="width: 100%"
            fit
            border
          >
            <el-table-column prop="CLIENT_NAME" label="班组名称" align="center"></el-table-column>
            <el-table-column prop="WorkVehicle" label="出动车辆" align="center"></el-table-column>
            <el-table-column prop="AllVehicle" label="全部车辆" align="center"></el-table-column>
          </el-table>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
// 引入导出Excel函数
import export2Excel from '@/utils/exportExcel/index.js'
import tool from '@/Tool.js'
export default {
  data () {
    return {
      titleWindow: '',
      titlePara: '',
      list: [],
      para: '1',
      date: '',
      teamValue: '',
      show: false
    }
  },
  created () {
    this.date = tool.formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd')
  },
  methods: {
    handleCommand (command) {
        if (command === '按作业点数统计') {
          this.titleWindow = '按作业点数出车统计信息表'
          this.titlePara = '作业点数（个数）'
          this.getDataForPoint()
        }
        if (command === '按出行距离统计') {
          this.titleWindow = '按出行距离出车统计信息表'
          this.titlePara = '出行距离（公里）'
          this.getDataForDistance()
        }
    },
    search () {
      if (this.titleWindow === '按作业点数出车统计信息表') {
        this.getDataForPoint()
      }
      if (this.titleWindow === '按出行距离出车统计信息表') {
        this.getDataForDistance()
      }
    },
    async getDataForPoint () {
      this.show = true
      var url = '/DataListCompany/GetVehicleWorkCCApi?WORKDATE=' + this.date + '&CLIENT_NO=' + localStorage.getItem('CLIENT_NO') + '&Type=1&DISTANCE=1&NUM=' + this.para
      const { data } = await this.$Http.get(url)
      this.list = data
    },
    async getDataForDistance () {
      this.show = true
      var url = '/DataListCompany/GetVehicleWorkCCApi?WORKDATE=' + this.date + '&CLIENT_NO=' + localStorage.getItem('CLIENT_NO') + '&Type=0&DISTANCE=' + this.para + '&NUM=1'
      const { data } = await this.$Http.get(url)
      this.list = data
    },
    closeWindow () {
      this.show = false
      this.para = '1'
      this.date = tool.formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd')
    },
  }
}
</script>

<style scoped lang="less">
.attendance {
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 20px;
  position: relative;
  cursor: default;
  text-align: center;
//   border-right:2px solid #007ACC;
  & > span:hover {
    color: #007ACC;
  }
  .work_area_list {
    width: 220px;
    // height: 78px;
    border: 1px solid #ccc;
    background-color: #f3f3f3;
    position: absolute;
    top:15px;
    z-index: 222222222222;
    span:last-child{
      border-bottom: 0;
    }
    span {
      display: block;
      padding: 0 10px 0 10px;
      line-height: 26px;
      color: #333;
      border-bottom:1px solid #2ea9fa;
      &:hover {
        color: #fff;
        background-color: #2ea9fa;
      }
    }
  }
  .attendance_work_time {
    width: 600px;
    height: 260px;
    background-color: #fff;
    border: 1px solid #ccc;
    position: fixed;
    left: 50%;
    top: 130px;
    transform: translateX(-50%);
    z-index: 999;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 5px 3px #ccc;
    h2 {
      line-height: 30px;
      border-bottom: 1px solid #ccc;
      padding-left: 10px;
      color: #666;
      span {
        margin-right: 5px;
      }
      i {
        float: right;
        margin-right: 10px;
      }
    }
    .attendance_content {
      .el-form {
        width: 400px;
        margin: 50px auto;
        .el-form-item {
          margin-bottom: 30px;
        }
        /deep/.el-date-editor .el-range__icon {
          line-height: 18px;
        }
        /deep/.el-date-editor .el-range-separator {
          line-height: 18px;
        }
        /deep/.el-input__icon {
          line-height: 20px;
        }
        .attendance_btns {
          margin-top: 40px;
          text-align: center;
          .el-button {
            display: inline-block;
            padding: 0 10px;
            margin: 0 20px;
          }
        }
      }
    }
  }
  .attendance_records {
    width: 800px;
    height: 498px;
    top: 50%;
    transform: translate(-50%, -50%);
    .top_box {
      height: 30px;
      padding-left: 20px;
      border-bottom: 1px solid #ccc;
      .el-form {
        margin: 5px 0;
        display: flex;
        align-items: center;
      }
      .el-form-item {
        width: '100%';
        margin: 0;
        margin-right: 20px;
        /deep/.el-date-editor.el-input {
          width: 152px;
        }
        .el-select {
          width: 152px;
        }
      }
      .records_btns {
        margin-left: 20px;
        .el-button {
          display: inline-block;
          margin-right: 20px;
          padding: 0 5px;
        }
      }
    }
    .bottom_box {
      color: #333;
      padding-top: 5px;
      & > span {
        padding-right: 5px;
        display: inline-block;
        &:last-child {
          border: 0 none;
        }
        span {
          padding: 0 2px;
          border-bottom: 1px solid #ccc;
        }
        i {
          display: inline-block;
          width: 2px;
          height: 12px;
          background-color: #999;
          margin-left: 8px;
        }
      }
    }
    .attendance_records_content {
      height: calc(~'100% - 32px');
      .table_list {
        height: calc(~'100% - 60px');
        // overflow-y: auto;
        .el-table {
          height: 100%;
          /deep/.el-table__body-wrapper {
            height: calc(~'100% - 35px');
            overflow-y: auto;
          }
        }
      }
    }
  }

  .attendanceMonth_records {
    width: 800px;
    height: 298px;
    top: 50%;
    transform: translate(-50%, -50%);
    .top_box {
      height: 30px;
      padding-left: 20px;
      border-bottom: 1px solid #ccc;
      .el-form {
        margin: 5px 0;
        display: flex;
        align-items: center;
      }
      .el-form-item {
        margin: 0;
        margin-right: 20px;
        /deep/.el-date-editor.el-input {
          width: 152px;
        }
        .el-select {
          width: 152px;
        }
      }
      .records_btns {
        margin-left: 20px;
        .el-button {
          display: inline-block;
          margin-right: 20px;
          padding: 4px 14px;
        }
      }
    }
    .bottom_box {
      color: #333;
      padding-top: 5px;
      & > span {
        padding-right: 5px;
        display: inline-block;
        &:last-child {
          border: 0 none;
        }
        span {
          padding: 0 2px;
          border-bottom: 1px solid #ccc;
        }
        i {
          display: inline-block;
          width: 2px;
          height: 12px;
          background-color: #999;
          margin-left: 8px;
        }
      }
    }
    .attendance_records_content {
      height: calc(~'100% - 32px');
      .table_list {
        height: calc(~'100% - 60px');
        // overflow-y: auto;
        .el-table {
          height: 100%;
          /deep/.el-table__body-wrapper {
            height: calc(~'100% - 35px');
            overflow-y: auto;
          }
        }
      }
    }
  }
}
.minwidth230{
  min-width: 230px;
}
</style>